package com.glsc.ngateway.platform.repo.softLegal;

import com.glsc.ngateway.platform.domain.softLegal.SoftUpdate;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface SoftUpdateRepository extends JpaRepository<SoftUpdate, Integer>, JpaSpecificationExecutor<SoftUpdate> {

    @Query(value = "select m from SoftUpdate m where m.isDelete=0 " +
            "and (:#{#paramSearchDto.applicationDate} is null OR m.applicationDate= :#{#paramSearchDto.applicationDate}) " +
            "and (:#{#paramSearchDto.applicant} is null OR m.applicant LIKE CONCAT('%', :#{#paramSearchDto.applicant},'%') ) " +
            "and (:#{#paramSearchDto.applicantDepartment} is null OR m.applicantDepartment LIKE CONCAT('%', :#{#paramSearchDto.applicantDepartment},'%') ) " +
            "and (:#{#paramSearchDto.originalSoftwareFocalPointUnit} is null OR m.originalSoftwareFocalPointUnit LIKE CONCAT('%', :#{#paramSearchDto.originalSoftwareFocalPointUnit},'%') ) " +
            "and (:#{#paramSearchDto.newSoftwareFocalPointUnit} is null OR m.newSoftwareFocalPointUnit LIKE CONCAT('%', :#{#paramSearchDto.newSoftwareFocalPointUnit},'%') ) " +
            "and (:#{#paramSearchDto.upgradeMethod} is null OR m.upgradeMethod LIKE CONCAT('%', :#{#paramSearchDto.upgradeMethod},'%') ) " +
            "and (:#{#paramSearchDto.softwareEnableTime} is null OR m.softwareEnableTime= :#{#paramSearchDto.softwareEnableTime}) " +
            "and (:#{#paramSearchDto.changeReason} is null OR m.changeReason LIKE CONCAT('%', :#{#paramSearchDto.changeReason},'%') ) " +
            "and (:#{#paramSearchDto.softwareType} is null OR m.softwareType LIKE CONCAT('%', :#{#paramSearchDto.softwareType},'%') ) " +
            "and (:#{#paramSearchDto.softwareCategory} is null OR m.softwareCategory LIKE CONCAT('%', :#{#paramSearchDto.softwareCategory},'%') ) " +
            "and (:#{#paramSearchDto.fullSoftwareName} is null OR m.fullSoftwareName LIKE CONCAT('%', :#{#paramSearchDto.fullSoftwareName},'%') ) " +
            "and (:#{#paramSearchDto.softwareVendor} is null OR m.softwareVendor LIKE CONCAT('%', :#{#paramSearchDto.softwareVendor},'%') ) " +
            "and (:#{#paramSearchDto.softwareVersion} is null OR m.softwareVersion LIKE CONCAT('%', :#{#paramSearchDto.softwareVersion},'%') ) " +
            "and (:#{#paramSearchDto.remarks} is null OR m.remarks LIKE CONCAT('%', :#{#paramSearchDto.remarks},'%') )")
    Page<SoftUpdate> searchByParam(Pageable pageable, SoftUpdate paramSearchDto);

//    List<SoftUpdate> findAllBySoftwareNameAndIsDelete(String softwareName, Integer noDelete);


//    @Transactional
//    @Modifying
//    @Query(value = "update t_cmdb_cpu_detail set is_delete = :deleted where cpu_detail_code in :codes ", nativeQuery = true)
//    void updateIsDeleteByCodes(Integer deleted, List<String> codes);
//
//    @Transactional
//    @Modifying
//    @Query(value = "update t_cmdb_cpu_detail set is_delete = :deleted where location_id = :deviceDetailId and life_status = 1", nativeQuery = true)
//    void updateIsDeleteByDeviceDetailId(Integer deleted, Integer deviceDetailId);
//
//    List<SoftUpdate> findAllBySnAndIsDelete(String sn, Integer noDelete);
//
//    SoftUpdate findByCpuDetailId(Integer cpuDetailId);
//
//    List<SoftUpdate> findAllByCpuDetailCodeIn(List<String> collect);
//
//    List<SoftUpdate> findAllByDeviceCodeAndIsDelete(String deviceCode, Integer noDeleted);

}
